package com.tac.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tac.common.result.Result;
import com.tac.pojo.Strategy;
import com.tac.service.StrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/strategy")
@CrossOrigin
@Api(tags = "攻略或游记")
@Slf4j
public class StrategyController {
    @Autowired
    private StrategyService strategyService;


    /**
     * 查看全部攻略
     * @return
     */
    @GetMapping
    @ApiOperation("查看全部攻略或游记")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name = "page", required = true)
    })
    public Result<IPage<Strategy>> selectAll(long page, HttpServletRequest request){
        log.info("用户：{}，通过地址{}--请求查看全部攻略",request.getRemoteAddr(),request.getRequestURI());
        return strategyService.selectAll(page);
    }

    /**
     * 写游记
     * @param strategy
     * @return
     */
    @PostMapping("/{userId}")
    @ApiOperation("写游记或攻略")
    @ResponseStatus(HttpStatus.CREATED)
    public Result saveStrategy(@RequestBody Strategy strategy,@PathVariable Long userId,HttpServletRequest request){
        log.info("用户：{}，通过地址{}--请求写游记",request.getRemoteAddr(),request.getRequestURI());
        return strategyService.saveStrategy(strategy,userId);
    }
}
